package com.github.qingcheng.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.qingcheng.mapper.BrandMapper;
import com.github.qingcheng.pojo.Brand;
import com.github.qingcheng.pojo.PageResult;
import com.github.qingcheng.service.BrandService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 品牌业务类
 * @author GY
 * @version V1.0
 * @date 2025-01-21 08:43
 */
@Service
@RequiredArgsConstructor
public class BrandServiceImpl implements BrandService {
    private final BrandMapper brandMapper;

    @Override
    public PageResult findPage(Brand brand) {
        PageHelper.startPage(brand.getPage(),brand.getSize());
        List<Brand> brands = brandMapper.findPage(brand);
        Page<Brand>  result = (Page<Brand>) brands;
        return new PageResult((int) result.getTotal(),result.getResult());
    }

    @Override
    public void add(Brand brand) {
        brandMapper.add(brand);
    }

    @Override
    public void delete(Integer id) {
        brandMapper.delete(id);
    }

    @Override
    public Brand findById(Integer id) {
        return brandMapper.findById(id);
    }

    @Override
    public void update(Brand brand) {
        brandMapper.update(brand);
    }
}
